import React, { PureComponent, createRef } from 'react'

class HelloWorld extends PureComponent {
  test(){
    console.log("test-----")
  }
  render(){
    return (<h1>helloworld</h1>)
  }
}

export class App extends PureComponent {
  constructor(){
    super()
    this.state = {

    }
    this.HelloWorldRef = createRef()
  }
  getComponent(){
    // HelloWorldInstance.test()
    console.log(this.HelloWorldRef.current)
    this.HelloWorldRef.current.test()

  }
  render() {
    return (
      <div>
        <HelloWorld ref={this.HelloWorldRef}></HelloWorld>
        <button onClick={e=>this.getComponent()}>获取组件实例</button>
      </div>
    )
  }
}

export default App